package com.example.springbootweb_comprehensiveexample.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

//@WebFilter(urlPatterns = "/*")//'/*'意为拦截所有请求
public class DemoFilter implements Filter {
    @Override//初始化的方法，只调用一次
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("Fliter init初始化方法执行");
    }

    @Override//拦截到请求之后调用，多次调用
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("Fliter拦截到了请求。。。放行前的逻辑");
        //放行
        filterChain.doFilter(request, response);

        System.out.println("Fliter放行后的逻辑");
    }

    @Override//销毁方法，只调用一次
    public void destroy() {
        System.out.println("Fliter destroy销毁方法执行了");
    }
}

